package com.chenfan.mcn.controller;

import com.chenfan.mcn.extension.Res;
import com.chenfan.mcn.extension.excel.ExcelUtils;
import com.chenfan.common.extension.validation.groups.Add;
import com.chenfan.mcn.model.dto.LiveSessionSaveDTO;
import com.chenfan.mcn.model.dto.LiveSessionSearchDTO;
import com.chenfan.mcn.model.vo.LiveSessionDetailVO;
import com.chenfan.mcn.model.vo.LiveSessionListExportVO;
import com.chenfan.mcn.model.vo.LiveSessionListVO;
import com.chenfan.mcn.service.LiveSessionService;
import com.chenfan.privilege.common.config.SearchAuthority;
import com.chenfan.privilege.common.config.UrlAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 直播排期
 * @author: WQ
 * Date 2023/4/27
 * @描述
 */
@RestController
@RequestMapping("/LiveSession")
public class LiveSessionController {


    @Autowired
    private LiveSessionService liveSessionService;

    /**
     * 新建直播场次
     * @param liveSessionAddDTO
     * @return
     */
    @PostMapping("/add")
    @UrlAuth({"liveScheduling_add"})
    public Res<Long> add(@RequestBody @Validated(Add.class) LiveSessionSaveDTO liveSessionAddDTO){
        return Res.ok(liveSessionService.save(liveSessionAddDTO));
    }

    /**
     * 修改直播场次
     * @param liveSessionAddDTO
     * @return
     */
    @PostMapping("/update")
    @UrlAuth({"liveScheduling_edit"})
    public Res<Long> update(@RequestBody @Validated(Add.class) LiveSessionSaveDTO liveSessionAddDTO){
        return Res.ok(liveSessionService.save(liveSessionAddDTO));
    }

    /**
     * 作废直播场次
     * @param lsId
     * @return
     */
    @GetMapping("/invalid/{lsId}")
    @UrlAuth({"liveScheduling_invalid"})
    public Res<Boolean> invalid(@PathVariable Long lsId) {
        return Res.ok(liveSessionService.invalid(lsId));
    }

    /**
     * 直播排期
     * @param searchDTO
     * @return
     */
    @PostMapping("/list")
    @UrlAuth({"liveScheduling_search"})
    public Res<LiveSessionListVO> list(@SearchAuthority(filterCustomer = false)  LiveSessionSearchDTO searchDTO) {
        return Res.ok(liveSessionService.list(searchDTO));
    }

    /**
     * 直播场次-详情
     * @param lsId
     * @return
     */
    @GetMapping("/detail/{lsId}")
    public Res<LiveSessionDetailVO> detail(@PathVariable Long lsId) {
        return Res.ok(liveSessionService.detail(lsId));
    }

    /**
     * 直播排期导出
     *
     */
    @PostMapping("/exportExcel")
    @UrlAuth({"liveScheduling_exportLive"})
    public void exportExcel(@SearchAuthority(filterCustomer = false)  LiveSessionSearchDTO searchDTO, HttpServletResponse response) {
        List<LiveSessionListExportVO> exportList = liveSessionService.exportExcel(searchDTO);
        ExcelUtils.exportExcel(exportList, "直播场次导出", LiveSessionListExportVO.class, "直播场次导出.xlsx", response);
    }

}
